package com.handler;

import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.ObjectListing;
import com.amazonaws.services.s3.model.S3ObjectSummary;
import com.amazonaws.services.s3.transfer.MyTransferManager;

import java.util.List;

/**
 * 权限
 */
public class AuthorityHandler extends BaseHandler<String> {

    public AuthorityHandler(MyTransferManager transferManager) {
        super(transferManager);
    }

    @Override
    public void execute(String bucketName) {
        ObjectListing ol = s3Client.listObjects(bucketName);
        List<S3ObjectSummary> objects = ol.getObjectSummaries();
        System.out.println(" len = "+objects.size());
        for (S3ObjectSummary os: objects) {
//            System.out.println("* " + os.getKey());
            s3Client.setObjectAcl(
                    bucketName,
                    os.getKey(),
//                    CannedAccessControlList.Private
                    CannedAccessControlList.PublicRead
            );
        }
    }

}
